import request from "@/utils/request-base";
import mockRequest from '@/utils/mockRequest'

interface detailArrayData {
  "id": null,
  "orderId": null,
  "skuId": number,
  "skuName": string,
  "imgUrl": string,
  "orderPrice": number,
  "skuNum": number,
  "createTime": null,
  "sourceType": string,
  "sourceId": number,
  "splitTotalAmount": null,
  "splitActivityAmount": null,
  "splitCouponAmount": null,
  "refundStatus": "",
  "refundStatusString": "",
  "hasStock": null,
  "activityRule": null,
  "couponInfoList": null
}
export interface orderListData {
  totalAmount: number | string
  userAddressList: []
  tradeNo: string
  totalNum: number | string
  originalTotalAmount: number | string
  couponInfoList: []
  detailArrayList: detailArrayData[]
  activityReduceAmount: number | string
  orderDetailVoList: detailArrayData[]
}


//购物车列表
export interface CartListData {
  id: number;
  userId: string;
  skuId: number;
  cartPrice: number;
  skuNum: number;
  imgUrl: string;
  skuName: string;
  isChecked: number | string;
  createTime: string;
  operateTime: string;
  isOrdered: number;
  orderTime: string;
  sourceType: string;
  sourceId: number;
  skuPrice: number;
  couponInfoList: null;

}
//订单id列表
export interface OrderData {
  "consignee": string,
  "consigneeTel": string,
  "deliveryAddress": string,
  "paymentWay": string,
  "orderComment": string,
  "orderDetailList": orderDetailData[]
}
//用户地址
export interface UserAddressData {
  "id": string,
  "name": string,
  "tel": string,
  "address": string,
  "isDefault": boolean
}

//订单详情
export interface orderDetailData {
  id: null,
  orderId: null,
  skuId: number,
  skuName: string,
  imgUrl: string,
  orderPrice: number,
  skuNum: number,
  hasStock: null
}
//交易信息
export type tradeInfoData = {
  tradeNo: string
  consignee: string
  consigneeTel: string
  deliveryAddress: string
  paymentWay: string
  orderComment: string
  orderDetailList: orderDetailData[]
}
export interface tradeData {
  detailArrayList: detailArrayData[],
  originalTotalAmount: number,
  tradeNo: string,
  totalNum: number,
  totalAmount: number

}
//token
export interface tokenData {
  token: string
  code: number
  data: {
    nickName: string,
    name: string,
    userId: number,
    token: string
  }
  message: string
  ok: boolean

}
export interface gettokenData {
  phone: string,
  password: string
}
interface orderData {
  data: number
}
export interface payInfoData {
  "codeUrl": string,
  "orderId": number,
  "totalFee": number,
  "resultCode": string
}
export interface paySucessData {
  code: number,
  "message": string,
  "ok": boolean
}
export default {
  //获取购物车列表
  getCartList() {
    return request.get<any, any>("/api/cart/cartList");
  },
  //删除单个商品
  removeCartList(skuId: number) {
    return request.delete<any, null>(`/api/cart/deleteCart/${skuId}`);
  },
  //全选全不选
  reqBatchCheckCart(isChecked: number, skuIdList: any) {
    return request.post<any, null>(`/api/cart/batchCheckCart/${isChecked}`, skuIdList)

  },
  //切换商品选中状态
  reqCheckCart(skuID: number, isChecked: string | number) {
    return request.get<any, null>(`/api/cart/checkCart/${skuID}/${isChecked}`)
  },
  //获取用户地址
  getUserAddress() {
    return mockRequest.get<any, UserAddressData[]>('/api/user/userAddress/auth/findUserAddressList')
  },
  //获取支付信息
  reqPay(orderId: number) {
    return request.get<any, payInfoData>(`/api/payment/weixin/createNative/${orderId}`)
  },
  // 获取交易页面的商品信息
  reqTradeInfo() {
    return request.get<any, tradeData>('/api/order/auth/trade')
  },
  // 提交订单、获取支付信息
  reqSubmitOrder(data: tradeInfoData) {
    return request.post<any, null>(`/api/order/auth/submitOrder?tradeNo=${data.tradeNo}`, data)
  },
  //查询订单支付xinx
  reqPayment(orderId: string) {
    return request.get<any, paySucessData>(`/api/payment/weixin/queryPayStatus/${orderId}`)
  },
  //获取token
  getToken(params: gettokenData) {
    return request.post<any, tokenData>('/api/user/passport/login', params)
  }


};
